﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Wicresoft.Shell.Package.AppExp
{
    public class NormalPropertyItemObject : BasePropertyItemObject
    {
        private string iname;

        public NormalPropertyItemObject(TreeNode tn)
        {
            iname = tn.Text;
            _tn = tn;
        }


        protected override void SetProperties()
        {
            base.SetProperties();
            if (_tn != null)
            {
                if (_tn.Tag != null)
                {
                    string t_tag = _tn.Tag.ToString();
                    if (t_tag.StartsWith("FID"))
                    {
                        string function_ID = t_tag.Substring(3);
                        try
                        {
                            Workspace.GetDatabaseLogic().UpdateFunctionName(Convert.ToInt16(function_ID), iname);
                            _tn.Text = iname;
                        }
                        catch
                        {
                            MessageBox.Show("Operation Failed!");
                        }
                    }
                    else
                    {
                        string app_ID = t_tag;
                        try
                        {
                            Workspace.GetDatabaseLogic().UpdateApplicationName(Convert.ToInt16(app_ID), iname);
                            _tn.Text = iname;
                        }
                        catch
                        {
                            MessageBox.Show("Operation Failed!");
                        }
                    }
                }
            }
        }

        
        [Category("General")]
        [Description("Name property")]
        public string Name
        {
            get 
            {
                return iname;
            }
            set 
            {
                iname = value;
                SetProperties();
            }
        }
    }
}
